<template>
	<uni-nav-bar title="我的存货" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view class="package space-between" @click="navTo('groupBenefits/upGgoods')">
		<text>当前提货单有{{numDev}}件货</text>
		<uni-icons type="forward" size="20" color="#666"></uni-icons>
	</view>
	<view class="package" :style="{padding:'20rpx 0px',marginTop:isH5?'15rpx':'0px'}" v-for="(item,index) in orderLists"
		:key='item.id'>
		<view class="packageLsit" @click="navTo('shopp/Shopkeeper?id='+item.id)">
			<image src="../../static/groupBenefits/shop.png" mode=""></image>
			<text>{{item.name}}</text>
			<uni-icons type="forward" size="19" color="#666"></uni-icons>
		</view>
		<view v-for="(items,indexs) in item.goods_list" :key="indexs">
			<ShopList :money="'stock'" @delivery="delivery" :shoppAll="items" :jump="'group'"></ShopList>
		</view>
	</view>
	<view class="column fillings" :style="{ height: pageHeight + 'px' }" v-if="orderLists.length<1">
		<image :src="Empty"></image>
		<text>暂无存货记录</text>
	</view>
	<!-- 提货弹框 -->
	<uni-popup ref="deliveryPopup" type="bottom">
		<deliveryNum :methodList="methodList" :methodAll="methodAll" @submit="closeDelivery"></deliveryNum>
	</uni-popup>
</template>

<script setup lang="ts">
	import {navBack,navTo} from '@/utils/navigator';
	import ShopList from '@c/groupBenefits/shopGrid.vue';
	import deliveryNum from '@c/order/delivery.vue';
	import { Empty } from '@/utils/Static';
	import {ref,Ref,onMounted} from 'vue';
	import {onShow} from '@dcloudio/uni-app';
	import {toPublish} from '@mqtt';
	import {isH5} from '@/utils/platform';
	import {stock,method,rewardNumber} from '@/gql/group';
	import {getDriverID} from '@/stores/driverID';
  /**
   * 我的存货主页
   * @param user_id  用户ID
   * @param deliveryPopup  提货框值
   * @param pageHeight  存货列表高度
   * @param orderLists  存货列表
   * @param numDev  当前提货件数
   * @param methodList  当前商品提货方式
   * @param methodAll  当前提货商品数据
   */
	const user_id = getDriverID();
	const deliveryPopup = ref(null);
	const pageHeight = ref()
	const orderLists = ref([]);
	
	const numDev=ref('')

	const methodList = ref([])
	const methodAll: Ref < any > = ref({});
	onMounted(() => {
		const num = isH5 ? 80 : 135
		uni.getSystemInfo({
			success: function(res) {
				pageHeight.value = (res.windowHeight - num).toString();
			},
		});
	});
	onShow(() => {
		orderLists.value = []
		init()
		deliNum()
	})
/**
 * 初始化存货列表
 * * @param user_id  用户ID
 */
	function init() {
		const payload = {
			query: stock,
			variables: {
				user_id
			},
		};
		toPublish(
			'ql/store/getMyLibrary',
			payload,
			(obj: any) => {
				const {
					my_library
				} = obj.data;
				orderLists.value = my_library;
			}
		);
	}
  /**
   * 初始化提货数据
   * @param user_id  用户ID
   * @param numDev  提货件数
   */
	function deliNum(){
		const payload = {
			query: rewardNumber,
			variables: {
				user_id
			},
		};
		toPublish(
			'ql/store/getHexiaoGoodsNums',
			payload,
			(obj: any) => {
				const {
					get_hexiao_nums
				} = obj.data;
				numDev.value = get_hexiao_nums.nums;
			}
		);
	}
	/**
   * 存储获取提货商品数据
	 * @param {Object} num 提货商品数据
   * @param methodList  当前商品提货方式
   * @param methodAll  当前提货商品数据
   * @return 打开提货弹框
	 */
	function delivery(num:any) {
		methodAll.value = num
		const payload = {
			query: method,
			variables: {
				goods_id: Number(num.goodsId)
			},
		};
		toPublish('ql/store/getDispatchType', payload, (obj: any) => {
			const {
				get_dispatch_list
			} = obj.data;
			if (get_dispatch_list.length > 0) {
				methodList.value = get_dispatch_list
				openDelivery()
			}
		});
	}
  /**
   * 打开提货框
   */
	function openDelivery() {
		deliveryPopup.value.open();
	}
   /**
    * 关闭提货框
    */
	function closeDelivery() {
		deliveryPopup.value.close();
	}
</script>

<style scoped lang="less">
	@import url('../order/less/populic.less');

	.packageLsit {
		width: 100%;
		padding: 0px 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;

		image {
			width: 50rpx;
			height: 50rpx;
		}

		text {
			font-size: 30rpx;
			font-weight: 400;
			color: #181818;
			margin: 0px 10rpx;
		}
	}
</style>
